﻿using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using ZeroSum.Domain.Repositories;
using ZeroSum.Extend.EFCore.MySql.EntityFrameworks;
using ZeroSum.Infrastructure.UnitTests.DomainTestBase;

namespace ZeroSum.Infrastructure.UnitTests.EntityFrameworks;

public class RepositoryTestBase
{
    protected static string DeleteTestDomainName = "test03";
    protected static long DeleteTestDomainId = 3;

    protected static TestDomain DeleteTestDomain = new()
    {
        Name = DeleteTestDomainName,
        Id = DeleteTestDomainId
    };

    protected static TestDomain DeleteTestDomain2 = new()
    {
        Name = "test04",
        Id = 4
    };

    protected readonly IRepository<TestDomain> Repository;

    public RepositoryTestBase()
    {
        var dbOptions = new DbContextOptionsBuilder<ZeroSumDbContext>()
            .UseInMemoryDatabase("in-memory").Options;
        var dbContext = new ZeroSumDbContext(dbOptions);
        var unitOfWork = new EFCoreUnitOfWork<ZeroSumDbContext>(dbContext);
        Repository = new EfCoreRepository<ZeroSumDbContext, TestDomain>(dbContext, unitOfWork);
    }

    protected static IEnumerable<TestDomain> GetInitData()
    {
        return new List<TestDomain>
        {
            new()
            {
                Id = 1,
                Name = "test01"
            },
            new()
            {
                Id = 2,
                Name = "test02"
            },
            DeleteTestDomain,
            DeleteTestDomain2
        };
    }
}